/*************************************************************************
 * File Name:    Divide_Two_Integers.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: 2013-11-15 14:15:55
 * 
 * Description:  
 |------------------------------------------------------------------------
 | Problem: Divide Two Integers
 |
 | Divide two integers without using multiplication, division and mod operator.
 |------------------------------------------------------------------------
 ************************************************************************/

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>

using namespace std;

class Solution {
private:
    unsigned un_divide(unsigned dividend, unsigned div)
    {
        unsigned d;
        unsigned ans = 0;
        
        while (dividend >= div) {
            for (d = 1; ((unsigned long long)div << d) <= dividend; ++d);
            ans |= (1 << (d - 1));
            dividend -= div << (d - 1);
        }
        return ans;
    }

public:
    int divide(int dividend, int divisor)
    {
        bool negative = false;
        
        unsigned un_dividend, un_divisor;
        
        if (dividend < 0) {
            un_dividend = -dividend;
            negative = !negative;
        } else {
            un_dividend = dividend;
        }
        
        if (divisor < 0) {
            un_divisor = -divisor;
            negative = !negative;
        } else {
            un_divisor = divisor;
        }
        
        unsigned ans = un_divide(un_dividend, un_divisor);
        return negative ? -ans : ans;
    }
};

int
main(int argc, char *argv[])
{
    Solution sol;

    cout << sol.divide(-2147483648, 1) << endl;

    return 0;
}
